var consultationId;

function consult() {
    ajax({
        url: "/api/order/submit",
        type: "post",
        dataType: "json",
        headers: {},
        data: {matchId: $.paramToObj(window.location.href).id},
        success: function (result) {
            $(".footer button").addClass("disable").on("click", function (event) {
                event.preventDefault();
                openWebview("my-orderdetail", {id: result.data.consultationId});
                return false;
            });
            setTimeout(function () {
                $(".footer button").html("已&nbsp;经&nbsp;咨&nbsp;询")
            }, 2000);
            openWebview("home-orderdetail", {id: result.data.consultationId});
        }
    });
}

function onPageReady() {
    ajax({
        url: "/api/match/myDetail?matchId=" + $.paramToObj(window.location.href).id,
        type: "post",
        dataType: "json",
        headers: {},
        data: {id: ""},
        success: function (result) {
            consultationId = result.data.consultationId;
            $("body").render("#main", result.data);
            $(".footer").render("#footer");
            if (result.data.hasConsulted) {
                $(".footer button").addClass("disable").html("已&nbsp;经&nbsp;咨&nbsp;询").on("click", function (event) {
                    event.preventDefault();
                    openWebview("my-orderdetail", {id: consultationId});
                    return false;
                });
            } else {
                $(".footer button").on("click", function (event) {
                    event.preventDefault();
                    if (!$(".footer button").is('.disable')) {
                        consult();
                    }
                    return false;
                });

            }
            var item;
            var i = 0;
            for (i in result.data.pass) {
                item = result.data.pass[i];
                $(".conformity ul").render("#li", item);
            }
            if (!i) {
                $(".conformity ul").render("#li", {name: '无'});
            }
            i = 0;
            for (i in result.data.fail) {
                item = result.data.fail[i];
                $(".inconformity ul").render("#li", item);
            }
            if (!i) {
                $(".inconformity ul").render("#li", {name: '无'});
            }
            i = 0;
            for (i in result.data.todo) {
                item = result.data.todo[i];
                $(".culture ul").render("#li", item);
            }
            if (!i) {
                $(".culture ul").render("#li", {name: '无'});
            }
            item = new PolicyBean(result.data.policyInfo);
            $(".detail").render("#detail", item);
        }
    });
}